#version 130

in vec3 LightDirectionTangent;
in vec3 Position;
in vec3 Normal;
in vec4 TexCoord;


uniform vec3 Kd; // Diffuse reflectivity
uniform vec3 Ld; // Light source intensity

uniform sampler2D Tex1;
uniform sampler2D normalMap;

out vec4 FragColor;

varying vec3 tangentSurface2light;
varying vec3 tangentSurface2view;

void main() 
{
	
	// The diffuse shading equation
	vec2 coordUV = vec2(TexCoord.x, TexCoord.y);
	vec3 texColor = vec3(texture( Tex1, coordUV ));

	vec3 TextureNormal_tangentspace = normalize(texture( normalMap, coordUV ).rgb*2.0 - 1.0);
	vec3 LightIntensity =  Ld * Kd * max(dot( tangentSurface2light, TextureNormal_tangentspace ),0.0) + 0.1;

	FragColor  = vec4 (texColor * LightIntensity * 0.7, 1.0);
}